this was partially automatic and partially manual.
#include <cstdarg>
#include <cstdio>
-void gbser__db(int l, const char* msg, ...)
+void gbser_db(int l, const char* msg, ...)
{
va_list ap;
va_start(ap, msg);
*/
int gbser_avail(void* handle)
{
- return gbser__fill_buffer(handle, 1, nullptr);
+ return gbser_fill_buffer(handle, 1, nullptr);
}
/* Read as many bytes as are available without blocking. At most |len|
int got = 0;
while (len > 0) {
- int rc = gbser__fill_buffer(handle, len, nullptr);
+ int rc = gbser_fill_buffer(handle, len, nullptr);
if (rc < 0) {
/* error */
return rc;
/* nothing available */
break;
}
- got += gbser__read_buffer(handle, &buf, &len);
+ got += gbser_read_buffer(handle, &buf, &len);
}
return got;
while (len > 0 && ms != 0) {
int rc;
- if (rc = gbser__fill_buffer(handle, len, &ms), rc < 0) {
+ if (rc = gbser_fill_buffer(handle, len, &ms), rc < 0) {
return rc;
}
- got += gbser__read_buffer(handle, &buf, &len);
+ got += gbser_read_buffer(handle, &buf, &len);
}
return got;
*/
-#ifndef __GBSER_H
-#define __GBSER_H
+#ifndef GBSER_H_INCLUDED_
+#define GBSER_H_INCLUDED_
#include <cstddef> // for size_t
const char* fix_win_serial_name_r(const char* comname, char* obuf, size_t len);
const char* fix_win_serial_name(const char* comname);
-#endif /* GBSER_H */
+#endif /* GBSER_H_INCLUDED_ */
};
/* Wrapper to safely cast a void * into a gbser_handle */
-static gbser_handle* gbser__get_handle(void* p)
+static gbser_handle* gbser_get_handle(void* p)
{
auto* h = (gbser_handle*) p;
assert(h->magic == MYMAGIC);
{
gbser_handle* h;
- gbser__db(4, "gbser_init(\"%s\")\n", port_name);
+ gbser_db(4, "gbser_init(\"%s\")\n", port_name);
h = (gbser_handle*) xcalloc(sizeof *h, 1);
h->magic = MYMAGIC;
*/
void gbser_deinit(void* handle)
{
- gbser_handle* h = gbser__get_handle(handle);
+ gbser_handle* h = gbser_get_handle(handle);
tcsetattr(h->fd, TCSAFLUSH, &h->old_tio);
close(h->fd);
int gbser_set_port(void* handle, unsigned speed, unsigned bits, unsigned parity, unsigned stop)
{
- gbser_handle* h = gbser__get_handle(handle);
+ gbser_handle* h = gbser_get_handle(handle);
speed_t s;
static unsigned bit_flags[] = {
return tcsetattr(h->fd, TCSADRAIN, &h->new_tio) ? gbser_ERROR : gbser_OK;
}
-unsigned gbser__read_buffer(void* handle, void** buf, unsigned* len)
+unsigned gbser_read_buffer(void* handle, void** buf, unsigned* len)
{
- gbser_handle* h = gbser__get_handle(handle);
+ gbser_handle* h = gbser_get_handle(handle);
unsigned count = *len;
auto* cp = (unsigned char*) *buf;
if (count > h->inbuf_used) {
* be updated to indicate the remaining time on exit.
* Returns the number of bytes available (>=0) or an error code (<0).
*/
-int gbser__fill_buffer(void* handle, unsigned want, unsigned* ms)
+int gbser_fill_buffer(void* handle, unsigned want, unsigned* ms)
{
int rc;
- gbser_handle* h = gbser__get_handle(handle);
+ gbser_handle* h = gbser_get_handle(handle);
if (want > BUFSIZE) {
want = BUFSIZE;
*/
int gbser_flush(void* handle)
{
- gbser_handle* h = gbser__get_handle(handle);
+ gbser_handle* h = gbser_get_handle(handle);
h->inbuf_used = 0;
if (tcflush(h->fd, TCIFLUSH)) {
return gbser_ERROR;
*/
int gbser_write(void* handle, const void* buf, unsigned len)
{
- gbser_handle* h = gbser__get_handle(handle);
+ gbser_handle* h = gbser_get_handle(handle);
const char* bp = (const char*) buf;
int rc;
while (len > 0) {
int is_port = 0;
if (fd = open(port_name, O_RDWR | O_NOCTTY), fd == -1) {
- gbser__db(1, "Failed to open port (%s) to check its type\n", strerror(errno));
+ gbser_db(1, "Failed to open port (%s) to check its type\n", strerror(errno));
return 0;
}
#define MYMAGIC 0x91827364
#define BUFSIZE 512
-void gbser__db(int l, const char* msg, ...);
-int gbser__fill_buffer(void* h, unsigned want, unsigned* ms);
-unsigned gbser__read_buffer(void* handle, void** buf, unsigned* len);
+void gbser_db(int l, const char* msg, ...);
+int gbser_fill_buffer(void* h, unsigned want, unsigned* ms);
+unsigned gbser_read_buffer(void* handle, void** buf, unsigned* len);
#define DEV_PREFIX "\\\\.\\\\"
/* Wrapper to safely cast a void * into a gbser_handle */
-static gbser_handle* gbser__get_handle(void* p)
+static gbser_handle* gbser_get_handle(void* p)
{
gbser_handle* h = (gbser_handle*) p;
assert(h->magic == MYMAGIC);
gbser_handle* h = (gbser_handle*) xcalloc(1, sizeof(*h));
const char* xname = fix_win_serial_name(port_name);
- gbser__db(2, "Translated port name: \"%s\"\n", xname);
+ gbser_db(2, "Translated port name: \"%s\"\n", xname);
h->magic = MYMAGIC;
*/
void gbser_deinit(void* handle)
{
- gbser_handle* h = gbser__get_handle(handle);
+ gbser_handle* h = gbser_get_handle(handle);
CloseHandle(h->comport);
int gbser_set_port(void* handle, unsigned speed, unsigned bits, unsigned parity, unsigned stop)
{
- gbser_handle* h = gbser__get_handle(handle);
+ gbser_handle* h = gbser_get_handle(handle);
DCB tio;
if (bits < 5 || bits > 8) {
return gbser_OK;
}
-unsigned gbser__read_buffer(void* handle, void** buf, unsigned* len)
+unsigned gbser_read_buffer(void* handle, void** buf, unsigned* len)
{
- gbser_handle* h = gbser__get_handle(handle);
+ gbser_handle* h = gbser_get_handle(handle);
unsigned count = *len;
unsigned char* cp = (unsigned char*) *buf;
if (count > h->inbuf_used) {
* be updated to indicate the remaining time on exit.
* Returns the number of bytes available (>=0) or an error code (<0).
*/
-int gbser__fill_buffer(void* handle, unsigned want, unsigned* ms)
+int gbser_fill_buffer(void* handle, unsigned want, unsigned* ms)
{
int rc;
- gbser_handle* h = gbser__get_handle(handle);
+ gbser_handle* h = gbser_get_handle(handle);
if (want > BUFSIZE) {
want = BUFSIZE;
*/
int gbser_flush(void* handle)
{
- gbser_handle* h = gbser__get_handle(handle);
+ gbser_handle* h = gbser_get_handle(handle);
h->inbuf_used = 0;
if (!PurgeComm(h->comport, PURGE_RXCLEAR)) {
return gbser_ERROR;
*/
int gbser_write(void* handle, const void* buf, unsigned len)
{
- gbser_handle* h = gbser__get_handle(handle);
+ gbser_handle* h = gbser_get_handle(handle);
DWORD nwritten;
const char* bp = (const char*) buf;
/* Not sure we need to spin here - but this'll work even if we don't */
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include <array> // for array
+#include <cctype> // for isprint
+#include <cstdarg> // for va_end, va_list, va_start
+#include <cstdio> // for size_t, sprintf, fread, fclose, feof
+#include <cstdint> // for uint32_t, int32_t, int16_t, uint16_t
+#include <cstdlib> // for strtod, strtoul
+#include <cstring> // for strlen, memcmp, memcpy
+#include <ctime> // for time_t, tm
+
+#include <QByteArray> // for QByteArray
+#include <QIntegerForSize> // for qPrintable
+#include <QString> // for QString
+#include <QVector> // for QVector
+
#include "defs.h"
-#include "gbser.h"
-#include "grtcirc.h"
-#include <cstdio>
-#include <cstdlib>
+#include "gbser.h" // for gbser_set_port, gbser_deinit, gbse...
+
#define MYNAME "WBT-100/200"
#define NL "\x0D\x0A"
}
/* Decompose binary date into discreet fields */
-#define _SPLIT_DATE(tim) \
- int sec = (((tim) >> 0) & 0x3F); \
- int min = (((tim) >> 6) & 0x3F); \
- int hour = (((tim) >> 12) & 0x1F); \
- int mday = (((tim) >> 17) & 0x1F); \
- int mon = (((tim) >> 22) & 0x0F); \
- int year = (((tim) >> 26) & 0x3F);
+std::array<int, 6> split_date(uint32_t tim)
+{
+ int sec = (((tim) >> 0) & 0x3F);
+ int min = (((tim) >> 6) & 0x3F);
+ int hour = (((tim) >> 12) & 0x1F);
+ int mday = (((tim) >> 17) & 0x1F);
+ int mon = (((tim) >> 22) & 0x0F);
+ int year = (((tim) >> 26) & 0x3F);
+ return {sec, min, hour, mday, mon, year};
+}
static time_t decode_date(uint32_t tim)
{
- _SPLIT_DATE(tim)
+ auto [sec, min, hour, mday, mon, year] = split_date(tim);
struct tm t;
t.tm_sec = sec;
static int check_date(uint32_t tim)
{
- _SPLIT_DATE(tim)
+ auto [sec, min, hour, mday, mon, year] = split_date(tim);
/* Sanity check the date. We don't allow years prior to 2004 because zero in
* those bits will usually indicate that we have an altitude instead of a